<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%><%@page import="java.io.*"%><%
	File f = (File)request.getAttribute("downloadFile");

	String fileName="";
	FileInputStream fis = null;
	try {
		fileName=f.getName();		
		
		String fileExt=fileName.substring(fileName.lastIndexOf(".")+1).toLowerCase();
	
		String contentType="application/octet-stream";
		if("jpe,jpeg,jpg".indexOf(fileExt)!=-1) {
			contentType="image/jpeg";
		} else if("gif".equals(fileExt)) {
			contentType="image/gif";
		} else {
			
		}
		response.addHeader("Content-Disposition","attachment; filename="+
			(new String(fileName.getBytes("UTF-8"),"iso8859_1"))+"");
		
		response.setContentType(contentType);
		
		byte[] b=new byte[1024];
		int read=0;
		
		fis = new FileInputStream(f);
		
		response.addHeader("Content-Length", fis.available()+"");
		
		OutputStream output = response.getOutputStream();
		while((read=fis.read(b))!=-1){
			output.write(b,0,read);
			output.flush();
		}
		
		fis.close();
				
		output.close();
	} catch (Exception e) {
		try {
			out.println("Open file "+fileName+" error！");
		} catch (IOException e1) {
			//e1.printStackTrace();
		}
	}finally{
		try{
			fis.close();
		}catch(Exception e){
			
		}
		if(((String)request.getAttribute("downloadFileDelete"))
				.toLowerCase().equals("yes")){
			f.delete();
		}
	}
%>